package com.wceManage.services.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wceManage.beans.EUser;
import com.wceManage.beans.page.PageList;
import com.wceManage.data.mapper.BaseMapper;
import com.wceManage.data.mapper.EUserMapper;
import com.wceManage.services.EmilyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author jiangwei
 * @since 20/5/5
 */
@Service
public class EmilyUserServiceImpl extends BaseServiceImpl<EUser> implements EmilyUserService {

    @Autowired(required = false)
    private EUserMapper userMapper;

    @Override
    public BaseMapper<EUser> getMapper() {
        return userMapper;
    }

    @Override
    public void save(EUser user) {
        userMapper.insert(user);
    }

    @Override
    public int updateStatusOfPhone(String phone) {
        return userMapper.updateByPhone(phone);
    }

    @Override
    public List<EUser> findAll(Map map) {
        return userMapper.selectAll(map);
    }

    @Override
    public PageList queryPage(PageList pageList, EUser user) {
        Page<EUser> page;
        int pageStart;
        if (pageList.getiDisplayLength() == -1) {//不分页
            pageStart = 1;
            page = PageHelper.startPage(pageStart, 10000, false);
        } else {
            pageStart = pageList.getiDisplayStart() / pageList.getiDisplayLength() + 1;
            page = PageHelper.startPage(pageStart, pageList.getiDisplayLength());
        }
        getMapper().queryList(user);
        pageList.setiTotalRecords(page.getTotal());
        pageList.setiTotalDisplayRecords(pageList.getiTotalRecords());
        pageList.setAaData(page.getResult());
        return pageList;
    }
}
